package com.platform.controller;

import com.platform.entity.GoodsSpecificationEntity;
import com.platform.entity.GroupPurchaseEntity;
import com.platform.service.GroupPurchaseService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/groupPurchase")
public class GroupPurchaseController {
    @Autowired
    private GroupPurchaseService groupPurchaseService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<GroupPurchaseEntity> goodsSpecificationList = groupPurchaseService.queryList(query);
        int total = groupPurchaseService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(goodsSpecificationList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
    /**
     * 查看信息
     */
    @RequestMapping(value = "/info/{id}",method = RequestMethod.GET)
    public R info(@PathVariable("id") Integer id) {
        GroupPurchaseEntity groupPurchaseEntity = groupPurchaseService.queryObject(id);

        return R.ok().put("groupPurchaseEntity", groupPurchaseEntity);
    }
    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public R save(@RequestBody GroupPurchaseEntity groupPurchaseEntity) {
        groupPurchaseService.save(groupPurchaseEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goodsspecification:update")
    public R update(@RequestBody GroupPurchaseEntity groupPurchaseEntity) {
        groupPurchaseService.update(groupPurchaseEntity);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    public R delete(@RequestBody Integer[] ids) {
        groupPurchaseService.deleteBatch(ids);
        return R.ok();
    }

}
